﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using memo;
using System.Collections.Generic;

namespace memoTest
{
    /// <summary>
    /// Class to test the functionality of Topic.
    /// Tests the constructors.
    /// </summary>
    [TestClass]
    public class TopicTest
    {
        /// <summary>
        /// Used only for the testing. The expected title in the test.
        /// </summary>
        private static string ExpectedTitle = "TitleName";
        /// <summary>
        /// Used only for the testing. The expected short description in the test.
        /// </summary>
        private static string ExpectedShortDescription = "ShortDescriptionText";

        /// <summary>
        /// Empty Constructor to speed up compilation.
        /// </summary>
        public TopicTest() { }

        /// <summary>
        /// Makes a new Topic and checks if the data is the same as given to the constructor.
        /// Has no subtopics nor contents.
        /// </summary>
        [TestMethod]
        public void NewTopicTest_NoSubTopics_NoContents()
        {
            Topic _Topic = new Topic(ExpectedTitle, ExpectedShortDescription);

            Assert.AreEqual(ExpectedTitle, _Topic.Title);
            Assert.AreEqual(ExpectedShortDescription, _Topic.ShortDescription);
            Assert.IsNull(_Topic.SubTopics);
        }

        /// <summary>
        /// Makes a new Topic and checks if the data is the same as given to the constructor.
        /// Has some subtopics but no contents.
        /// </summary>
        [TestMethod]
        public void NewTopicTest_SomeSubTopics_NoContents()
        {
            SubTopic ExpectedSubTopic1 = new SubTopic("Subtopic1", "asdasdasd");
            SubTopic ExpectedSubTopic2 = new SubTopic("Subtopic2", "qweqweqwe");

            List<SubTopic> ExpectedSubTopicList = new List<SubTopic>();

            ExpectedSubTopicList.Add(ExpectedSubTopic1);
            ExpectedSubTopicList.Add(ExpectedSubTopic2);

            Topic _Topic = new Topic(ExpectedTitle, ExpectedShortDescription, ExpectedSubTopicList);

            Assert.AreEqual(ExpectedTitle, _Topic.Title);
            Assert.AreEqual(ExpectedShortDescription, _Topic.ShortDescription);
            CollectionAssert.AreEqual(ExpectedSubTopicList, _Topic.SubTopics);

        }

        /// <summary>
        /// Makes a new Topic and checks if the data is the same as given to the constructor.
        /// Has some subtopics and some contents in those subtopics.
        /// </summary>
        [TestMethod]
        public void NewTopicTest_SomeSubTopics_SomeContents()
        {
            List<Content> ExpectedContentList1 = new List<Content>();
            List<Content> ExpectedContentList2 = new List<Content>();

            Random rnd = new Random();

            int Length = rnd.Next(5, 20);

            for (int i = 0; i < Length; i++)
            {
                ExpectedContentList1.Add(new Content("Content1_#" + i));
                ExpectedContentList2.Add(new Content("Content2_#" + i));
            }

            SubTopic ExpectedSubTopic1 = new SubTopic("Subtopic1", "asdasdasd", ExpectedContentList1);
            SubTopic ExpectedSubTopic2 = new SubTopic("Subtopic2", "qweqweqwe", ExpectedContentList2);

            List<SubTopic> ExpectedSubTopicList = new List<SubTopic>();

            ExpectedSubTopicList.Add(ExpectedSubTopic1);
            ExpectedSubTopicList.Add(ExpectedSubTopic2);

            Topic _Topic = new Topic(ExpectedTitle, ExpectedShortDescription, ExpectedSubTopicList);

            Assert.AreEqual(ExpectedTitle, _Topic.Title);
            Assert.AreEqual(ExpectedShortDescription, _Topic.ShortDescription);
            CollectionAssert.AreEqual(ExpectedSubTopicList, _Topic.SubTopics);
            int iii = 0;
            foreach (SubTopic subtopic in _Topic.SubTopics)
            {
                CollectionAssert.AreEqual(subtopic.Contents, ExpectedSubTopicList[iii].Contents);
                iii++;
            }

        }


        #region Régi cuccok
        /*
        /// <summary>
        /// beszédesebben! mivel és hogyan tesztel? mi az input és mi az elvárt eredmény?
        /// </summary>
        [TestMethod]
        public void TopicConstructorTest1()
        {
            string title = "Kakaóscsiga";
            string shortDescription = "Kakaós és csiga";
            Topic testTopic = new Topic(title, shortDescription);

            Assert.AreEqual(title, testTopic.Title);
            Assert.AreEqual(shortDescription, testTopic.ShortDescription);
        }

        [TestMethod]
        public void TopicConstructorTest2()
        {
            string title = "Kakaóscsiga";
            string shortDescription = "Kakaós és csiga";
            SubTopic subTopic = new SubTopic("Vaniliás csiga", "vaniliás és csiga");
            Topic testTopic = new Topic(title, shortDescription, subTopic);

            Assert.AreEqual(title, testTopic.Title);
            Assert.AreEqual(shortDescription, testTopic.ShortDescription);
            Assert.AreEqual(subTopic, testTopic.SubTopic[0]);
        }

        [TestMethod]
        public void TopicConstructorTest3()
        {
            string title = "Kakaóscsiga";
            string shortDescription = "Kakaós és csiga";
            SubTopic[] subTopic = { new SubTopic("Vaníliás csiga", "vaniliás és csiga"),
                                    new SubTopic("Szilvás bukta", "mert azt szeretem") };
            Topic testTopic = new Topic(title, shortDescription, subTopic);

            Assert.AreEqual(title, testTopic.Title);
            Assert.AreEqual(shortDescription, testTopic.ShortDescription);
            CollectionAssert.AreEqual(new List<SubTopic>(subTopic), testTopic.SubTopic);
        }
        */
        #endregion


    }
}
